import pytest
from Case_info.user.user import User
from TongYong.Get_data_file import Get_data_files
from Cases.case_tags import smoke,pre_online
from Case_info import sql_info

class TestLogin:

    @pre_online
    def test_login_email(self,mysql_connect,redis_connect):
        username = "tao09@hotmail.com"
        password = "123456"
        ret = User.login(username, password)
        assert ret.code == 0

        sql = "select id from fmz_user where email='%s';" % username
        user_obj = mysql_connect.fetchone(sql)

        redis_userid = redis_connect.get("token:%s" % ret.token)
        assert str(user_obj.id) == redis_userid

    @smoke
    def test_login_phone(self,mysql_connect,redis_connect):
        username = "15165862180"
        password = "123456"
        ret = User.login(username, password)
        assert ret.code == 0

        sql = "select id from fmz_user where phone='%s';" % username
        user_obj = mysql_connect.fetchone(sql)

        redis_userid = redis_connect.get("token:%s" % ret.token)
        assert str(user_obj.id) == redis_userid

    @pytest.mark.parametrize(*Get_data_files.form_mysql(sql_info.user_login_sql))
    def test_login(self, username, password,redis_connect,mysql_connect):
        ret = User.login(username, password)
        assert ret.code == 0

        sql = "select id from fmz_user where phone='%s';" % username
        user_obj = mysql_connect.fetchone(sql)

        redis_userid = redis_connect.get("token:%s" % ret.token)
        assert str(user_obj.id) == redis_userid


if __name__ == '__main__':
    pytest.main(['-vs', __file__])
